home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / hurd / hurdprio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-28  |  2.5 KB  |  88 lines

  1. /* Support code for dealing with priorities in the Hurd.
  2. Copyright (C) 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <hurd/resource.h>
  21. #include <hurd.h>
  22.  
  23. error_t
  24. _hurd_priority_which_map (enum __priority_which which, int who,
  25.               error_t (*function) (pid_t, struct procinfo *))
  26. {
  27.   unsigned int npids = 64, i;
  28.   pid_t pidbuf[npids], *pids;
  29.   error_t err;
  30.   struct procinfo *pip;
  31.   int pibuf[sizeof *pip + 5 * sizeof (pip->threadinfos[0])], *pi = pibuf;
  32.   unsigned int pisize = sizeof (pibuf) / sizeof (int);
  33.  
  34.   switch (which)
  35.     {
  36.     case PRIO_PROCESS:
  37.       npids = 1;
  38.       pids[0] = who;
  39.       err = 0;
  40.       break;
  41.  
  42.     case PRIO_PGRP:
  43.       err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
  44.       break;
  45.  
  46.     case PRIO_USER:
  47.       err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
  48.       break;
  49.  
  50.     default:
  51.       return EINVAL;
  52.     }
  53.  
  54.   for (i = 0; !err && i < npids; ++i)
  55.     {
  56.       if (which == PRIO_USER)
  57.     {
  58.       /* Get procinfo to check the owner.  */
  59.       int *oldpi = pi;
  60.       unsigned int oldpisize = pisize;
  61.       if (err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
  62.                              &pi, &pisize)))
  63.         continue;
  64.       if (pi != oldpi && oldpi != pibuf)
  65.         /* Old buffer from last call was not reused; free it.  */
  66.         __vm_deallocate (__mach_task_self (),
  67.                  (vm_address_t) oldpi, oldpisize * sizeof pi[0]);
  68.  
  69.       pip = (struct procinfo *) pi;
  70.       if (pip->owner != who)
  71.         continue;
  72.     }
  73.       else
  74.     pip = NULL;
  75.  
  76.       err = (*function) (pids[i], pip);
  77.     }
  78.  
  79.   if (pids != pidbuf)
  80.     __vm_deallocate (__mach_task_self (),
  81.              (vm_address_t) pids, npids * sizeof pids[0]);
  82.   if (pi != pibuf)
  83.     __vm_deallocate (__mach_task_self (),
  84.              (vm_address_t) pi, pisize * sizeof pi[0]);
  85.  
  86.   return err;
  87. }
  88.